package com.hbx.residential_service.controller;

import com.hbx.residential_service.domain.Admin;
import com.hbx.residential_service.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;
    @RequestMapping("/adminlogin.do")
    public String adminLogin(String adminname, String adminpwd, HttpSession session, Model model) throws Exception{
        Admin admin = adminService.adminLogin(adminname,adminpwd);
        if(admin!=null){
            model.addAttribute("adminname",admin.getAdminname());
            session.setAttribute("adminname",admin.getAdminname());//直到会话结束再消失
            return "admin-main";
        }
        else return "admin-failer";
    }
}
